package edu.bit.water.util;

import edu.bit.water.dto.DateUtils;

import java.text.DecimalFormat;

public class FormulaIntermediateVariable {
	private int id;
	private double formula1Variable1;
	private double formula1Variable2;
	private double formula2Variable1;
	private double formula2Variable2;
	private double formula3Variable1;
	private double formula3Variable2;
	//private double formula3Variable3;
	private double formula4Variable1;
	private double formula4Variable2;
	private double formula5Variable1;
	private double formula5Variable2;
	private double formula6Variable1;
	private double formula6Variable2;
	private double formula7Variable1;
	private double formula7Variable2;
	private double formula8Variable1;
	private double formula8Variable2;
	private double formula9Variable1;
	private double formula9Variable2;
	private double formula10Variable1;
	private double formula10Variable2;
	private final static String DIVWARNING = "除数为0";
	private DecimalFormat df = new DecimalFormat("#.0");
	
	
	public FormulaIntermediateVariable() {
		super();
	}
	
	public FormulaIntermediateVariable(int id,double formula1Variable1, double formula1Variable2, double formula2Variable1,
			double formula2Variable2, double formula3Variable1, double formula3Variable2, 
			double formula4Variable1, double formula4Variable2, double formula5Variable1, double formula5Variable2,
			double formula6Variable1, double formula6Variable2, double formula7Variable1, double formula7Variable2,
			double formula8Variable1, double formula8Variable2, double formula9Variable1, double formula9Variable2,
			double formula10Variable1, double formula10Variable2) {
		super();
		this.id = id;
		this.formula1Variable1 = formula1Variable1;
		this.formula1Variable2 = formula1Variable2;
		this.formula2Variable1 = formula2Variable1;
		this.formula2Variable2 = formula2Variable2;
		this.formula3Variable1 = formula3Variable1;
		this.formula3Variable2 = formula3Variable2;
		this.formula4Variable1 = formula4Variable1;
		this.formula4Variable2 = formula4Variable2;
		this.formula5Variable1 = formula5Variable1;
		this.formula5Variable2 = formula5Variable2;
		this.formula6Variable1 = formula6Variable1;
		this.formula6Variable2 = formula6Variable2;
		this.formula7Variable1 = formula7Variable1;
		this.formula7Variable2 = formula7Variable2;
		this.formula8Variable1 = formula8Variable1;
		this.formula8Variable2 = formula8Variable2;
		this.formula9Variable1 = formula9Variable1;
		this.formula9Variable2 = formula9Variable2;
		this.formula10Variable1 = formula10Variable1;
		this.formula10Variable2 = formula10Variable2;
	}

	public void showContent() {
//		System.out.println(id);
	}

	public boolean divisor() {
		if(this.formula1Variable2 == 0 || this.formula2Variable1+this.formula2Variable2 == 0 || this.formula3Variable2 == 0 || this.formula4Variable2 == 0
				|| this.formula5Variable2 == 0 || this.formula6Variable1+this.formula6Variable2 == 0 || this.formula7Variable1+this.formula7Variable2 == 0
				|| this.formula8Variable2 == 0 || this.formula9Variable1+this.formula9Variable2 == 0 || this.formula10Variable1+this.formula10Variable2 == 0)
			return false;
		return true;
	}
	//公式1
	private static void print(String args) {
//		System.out.println(args);
	}
	public double formula1() {
		//print("value1: " + this.formula1Variable1 );
		//print("value2: " + this.formula1Variable2 );
		double ret = 0.0;
		if(this.formula1Variable2 == 0.0) {
			return 0.0;
		}
		if(this.formula1Variable1 == 0)
			return ret;
		try {
			ret = (double)this.formula1Variable1/this.formula1Variable2;
		} catch (Exception e) {
			// TODO: handle exception
		}
		//print("计算结果: " + Double.valueOf(df.format(ret)));
		return Double.valueOf(df.format(ret));
	}
	//公式2
	public String formula2() {
		double ret = 0;
		if(this.formula2Variable1 + this.formula2Variable2 == 0.0) {
			return DIVWARNING;
		}
		if (this.formula2Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula2Variable1/(this.formula2Variable1+this.formula2Variable2);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	//公式3
	public String formula3() {
		double ret = 0;
		//print("value1: " + this.formula3Variable1);
		//print("value2: " + this.formula3Variable2);
		//DateUtils.printFxz();
		if(this.formula3Variable2 == 0) {
			return DIVWARNING;
		}
		if (this.formula3Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula3Variable1/this.formula3Variable2*1;
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	//公式4
	public String formula4() {
		double ret = 0;
		if(this.formula4Variable2 == 0.0) {
			return DIVWARNING;
		}
		if (this.formula4Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula4Variable1/this.formula4Variable2;
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	//公式5
	public String formula5() {
		double ret = 0;
		if(this.formula5Variable2 == 0.0) {
			return DIVWARNING;
		}
		if (this.formula5Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula5Variable1/this.formula5Variable2;
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	//公式6
	public String formula6() {
		double ret = 0;
		if(this.formula6Variable1 + this.formula6Variable2 == 0.0) {
			return DIVWARNING;
		}
		if (this.formula6Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula6Variable1/(this.formula6Variable1+this.formula6Variable2);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	//公式7
	public String formula7() {
		double ret = 0;
		if(this.formula7Variable2 + this.formula7Variable1 == 0.0) {
			return DIVWARNING;
		}
		if (this.formula7Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula7Variable1/(this.formula7Variable1+this.formula7Variable2);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	//公式8
	public String formula8() {
		double ret = 0;
		if(this.formula8Variable2 == 0.0) {
			return DIVWARNING;
		}
		if (this.formula8Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula8Variable1/this.formula8Variable2;
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	//公式9
	public String formula9() {
		double ret = 0;
		if(this.formula9Variable2 + this.formula9Variable1 == 0.0) {
			return DIVWARNING;
		}
		if (this.formula9Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula9Variable1/(this.formula9Variable1+this.formula9Variable2);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	//公式10
	public String formula10() {
		double ret = 0;
		if(this.formula10Variable1 + this.formula10Variable2 == 0.0) {
			return DIVWARNING;
		}
		if (this.formula10Variable1 == 0) {
			return "0.0%";
		}
		try {
			ret = this.formula10Variable1/(this.formula10Variable1+this.formula10Variable2);
		} catch (Exception e) {
			// TODO: handle exception
		}
		String string = df.format(ret*100)+"%";
		return string;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public double getFormula1Variable1() {
		return formula1Variable1;
	}
	public void setFormula1Variable1(double formula1Variable1) {
		this.formula1Variable1 = formula1Variable1;
	}
	public void setFormula1Variable1_string(String formula1Variable1) {
		if(formula1Variable1!=null)
			this.formula1Variable1 = Double.parseDouble(formula1Variable1);
		else
			this.formula1Variable1 = 0.0;
	}
	public double getFormula1Variable2() {
		return formula1Variable2;
	}
	public void setFormula1Variable2(double formula1Variable2) {
		this.formula1Variable2 = formula1Variable2;
	}
	public double getFormula2Variable1() {
		return formula2Variable1;
	}
	public void setFormula2Variable1(double formula2Variable1) {
		this.formula2Variable1 = formula2Variable1;
	}
	public double getFormula2Variable2() {
		return formula2Variable2;
	}
	public void setFormula2Variable2(double formula2Variable2) {
		this.formula2Variable2 = formula2Variable2;
	}
	public double getFormula3Variable1() {
		return formula3Variable1;
	}
	public void setFormula3Variable1(double formula3Variable1) {
		this.formula3Variable1 = formula3Variable1;
	}
	public double getFormula3Variable2() {
		return formula3Variable2;
	}
	public void setFormula3Variable2(double formula3Variable2) {
		this.formula3Variable2 = formula3Variable2;
	}
	public double getFormula4Variable1() {
		return formula4Variable1;
	}
	public void setFormula4Variable1(double formula4Variable1) {
		this.formula4Variable1 = formula4Variable1;
	}
	public double getFormula4Variable2() {
		return formula4Variable2;
	}
	public void setFormula4Variable2(double formula4Variable2) {
		this.formula4Variable2 = formula4Variable2;
	}
	public double getFormula5Variable1() {
		return formula5Variable1;
	}
	public void setFormula5Variable1(double formula5Variable1) {
		this.formula5Variable1 = formula5Variable1;
	}
	public double getFormula5Variable2() {
		return formula5Variable2;
	}
	public void setFormula5Variable2(double formula5Variable2) {
		this.formula5Variable2 = formula5Variable2;
	}
	public double getFormula6Variable1() {
		return formula6Variable1;
	}
	public void setFormula6Variable1(double formula6Variable1) {
		this.formula6Variable1 = formula6Variable1;
	}
	public double getFormula6Variable2() {
		return formula6Variable2;
	}
	public void setFormula6Variable2(double formula6Variable2) {
		this.formula6Variable2 = formula6Variable2;
	}
	public double getFormula7Variable1() {
		return formula7Variable1;
	}
	public void setFormula7Variable1(double formula7Variable1) {
		this.formula7Variable1 = formula7Variable1;
	}
	public double getFormula7Variable2() {
		return formula7Variable2;
	}
	public void setFormula7Variable2(double formula7Variable2) {
		this.formula7Variable2 = formula7Variable2;
	}
	public double getFormula8Variable1() {
		return formula8Variable1;
	}
	public void setFormula8Variable1(double formula8Variable1) {
		this.formula8Variable1 = formula8Variable1;
	}
	public double getFormula8Variable2() {
		return formula8Variable2;
	}
	public void setFormula8Variable2(double formula8Variable2) {
		this.formula8Variable2 = formula8Variable2;
	}
	public double getFormula9Variable1() {
		return formula9Variable1;
	}
	public void setFormula9Variable1(double formula9Variable1) {
		this.formula9Variable1 = formula9Variable1;
	}
	public double getFormula9Variable2() {
		return formula9Variable2;
	}
	public void setFormula9Variable2(double formula9Variable2) {
		this.formula9Variable2 = formula9Variable2;
	}
	public double getFormula10Variable1() {
		return formula10Variable1;
	}
	public void setFormula10Variable1(double formula10Variable1) {
		this.formula10Variable1 = formula10Variable1;
	}
	public double getFormula10Variable2() {
		return formula10Variable2;
	}
	public void setFormula10Variable2(double formula10Variable2) {
		this.formula10Variable2 = formula10Variable2;
	}
	
	
}
